package com.xh.petdogexpert.sys.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.xh.petdogexpert.base.BaseController;
import com.xh.petdogexpert.base.BaseException;
import com.xh.petdogexpert.base.ResponseData;
import com.xh.petdogexpert.sys.dto.Menu;
import com.xh.petdogexpert.sys.mapper.MenuMapper;
import com.xh.petdogexpert.sys.service.IMenuService;




@Controller
public class MenuController extends BaseController{

	@Autowired
	IMenuService menuService;
	
	@Autowired
	MenuMapper menuMapper;
	
	@RequestMapping(value="sys/getMenus")
	@ResponseBody
	public ResponseData getMenu() {
		Menu menu = new Menu();

		List<Menu> menuList = menuService.getMenus(menu);
		
		return new ResponseData(menuList);
	}
	
	
	@RequestMapping(value = "menu/queryMenus")
	@ResponseBody
	public ResponseData queryMenus(Menu menu) {

		ResponseData rData = new ResponseData();
		List<Menu> menus = menuService.queryMenus(menu);
		rData.setData(menus);
		return rData;
	} 


	@RequestMapping(value = "menu/getMenu")
	@ResponseBody
	public ResponseData getMenu(Menu menu) throws BaseException {

		ResponseData rData = new ResponseData();
		Menu rMenu = null;

		rMenu = menuService.getMenu(menu);
		rData.setData(rMenu);

		return rData;
	}
	
	@RequestMapping(value = "menu/addUpdateMenu")
	@ResponseBody
	public ResponseData addUpdateMenu(Menu menu) throws BaseException {

		ResponseData rData = new ResponseData();

		int id = menuService.addUpdateMenu(menu);
		if (menu.getId() != null) {
			rData.setMsg("修改用户成功");
		} else {
			rData.setMsg("新增用户成功");
		}
		rData.data = id;

		return rData;
	}

	@RequestMapping(value = "menu/deleteMenu")
	@ResponseBody
	public ResponseData deleteMenu(Menu menu) throws BaseException {

		ResponseData rData = new ResponseData();

		int count = menuService.deleteMenu(menu);
		rData.setData(count);

		return rData;
	}
}
